import INavigate from "../../Interfaces/INavigate";
import Oriented from "../../Constants/Oriented";
import G from "../../Utilities/Global";
import Constants from "../../Constants/Constants";
import EventDefines from "../../Constants/EventDefines";

/**
 * 折返跑
 * 遇到不能朝向的下方没有砖块的时候,掉头行走
 * created by Five on 2018-11-28 17:59:51
 */

export default class Patrol implements INavigate {
    settarget(node: cc.Node) {
    }
    setsize(s: number) {
    }
    oriented: any; speed: number;
    setdir(dir: any) {
        this.oriented = dir;
    }
    setspeed(sp: number) {
        this.speed = sp;
    }

    update(dt: number, node: cc.Node, aniNode: cc.Node) {
        let speed = this.oriented == Oriented.RIGHT ? this.speed : this.speed * -1;
        let target = node.position.add(cc.v2(speed * dt, 0));
        let forward = G().Calc.FW(target, this.oriented);
        let entityTar = G().CurScene.MapData.GetWallByPosition(forward);
        let entityTarDown = G().CurScene.MapData.GetWallByPosition(G().Calc.FD(target, this.oriented));
        if (!entityTar && entityTarDown) {
            node.position = node.position.add(cc.v2(speed * dt, 0));
        } else {
            this.oriented = this.oriented == Oriented.RIGHT ? Oriented.LEFT : Oriented.RIGHT;
            aniNode.is3DNode = true;
            aniNode.eulerAngles = this.oriented == Oriented.RIGHT ? Constants.OppsiteRotate : cc.Vec3.ZERO;
            G().CurScene.BoomTile(forward, true);
        }
    }
}